package com.wujilee.wujileemybatisdynamicsql.mapper;

import com.wujilee.wujileemybatisdynamicsql.entity.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.*;

import javax.annotation.Generated;
import java.util.Collection;
import java.util.List;
import java.util.Optional;

import static com.wujilee.wujileemybatisdynamicsql.mapper.UserDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

@Mapper
public interface UserMapper extends CommonSelectMapper, CommonCountMapper, CommonDeleteMapper, CommonInsertMapper<User>, CommonUpdateMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.817+08:00", comments="Source Table: sys_user")
    BasicColumn[] selectList = BasicColumn.columnList(userId, deptId, username, nickName, gender, phone, email, password, isAdmin, enabled, createBy, updateBy, pwdResetTime, createTime, updateTime, language);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.796+08:00", comments="Source Table: sys_user")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="UserResult", value = {
        @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="dept_id", property="deptId", jdbcType=JdbcType.BIGINT),
        @Result(column="username", property="username", jdbcType=JdbcType.VARCHAR),
        @Result(column="nick_name", property="nickName", jdbcType=JdbcType.VARCHAR),
        @Result(column="gender", property="gender", jdbcType=JdbcType.VARCHAR),
        @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
        @Result(column="is_admin", property="isAdmin", jdbcType=JdbcType.BIT),
        @Result(column="enabled", property="enabled", jdbcType=JdbcType.BIGINT),
        @Result(column="create_by", property="createBy", jdbcType=JdbcType.VARCHAR),
        @Result(column="update_by", property="updateBy", jdbcType=JdbcType.VARCHAR),
        @Result(column="pwd_reset_time", property="pwdResetTime", jdbcType=JdbcType.BIGINT),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.BIGINT),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.BIGINT),
        @Result(column="language", property="language", jdbcType=JdbcType.VARCHAR)
    })
    List<User> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.799+08:00", comments="Source Table: sys_user")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("UserResult")
    Optional<User> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.802+08:00", comments="Source Table: sys_user")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, user, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.802+08:00", comments="Source Table: sys_user")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, user, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.802+08:00", comments="Source Table: sys_user")
    default int deleteByPrimaryKey(Long userId_) {
        return delete(c ->
            c.where(userId, isEqualTo(userId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.803+08:00", comments="Source Table: sys_user")
    default int insert(User row) {
        return MyBatis3Utils.insert(this::insert, row, user, c ->
            c.map(userId).toProperty("userId")
            .map(deptId).toProperty("deptId")
            .map(username).toProperty("username")
            .map(nickName).toProperty("nickName")
            .map(gender).toProperty("gender")
            .map(phone).toProperty("phone")
            .map(email).toProperty("email")
            .map(password).toProperty("password")
            .map(isAdmin).toProperty("isAdmin")
            .map(enabled).toProperty("enabled")
            .map(createBy).toProperty("createBy")
            .map(updateBy).toProperty("updateBy")
            .map(pwdResetTime).toProperty("pwdResetTime")
            .map(createTime).toProperty("createTime")
            .map(updateTime).toProperty("updateTime")
            .map(language).toProperty("language")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.814+08:00", comments="Source Table: sys_user")
    default int insertMultiple(Collection<User> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, user, c ->
            c.map(userId).toProperty("userId")
            .map(deptId).toProperty("deptId")
            .map(username).toProperty("username")
            .map(nickName).toProperty("nickName")
            .map(gender).toProperty("gender")
            .map(phone).toProperty("phone")
            .map(email).toProperty("email")
            .map(password).toProperty("password")
            .map(isAdmin).toProperty("isAdmin")
            .map(enabled).toProperty("enabled")
            .map(createBy).toProperty("createBy")
            .map(updateBy).toProperty("updateBy")
            .map(pwdResetTime).toProperty("pwdResetTime")
            .map(createTime).toProperty("createTime")
            .map(updateTime).toProperty("updateTime")
            .map(language).toProperty("language")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.816+08:00", comments="Source Table: sys_user")
    default int insertSelective(User row) {
        return MyBatis3Utils.insert(this::insert, row, user, c ->
            c.map(userId).toPropertyWhenPresent("userId", row::getUserId)
            .map(deptId).toPropertyWhenPresent("deptId", row::getDeptId)
            .map(username).toPropertyWhenPresent("username", row::getUsername)
            .map(nickName).toPropertyWhenPresent("nickName", row::getNickName)
            .map(gender).toPropertyWhenPresent("gender", row::getGender)
            .map(phone).toPropertyWhenPresent("phone", row::getPhone)
            .map(email).toPropertyWhenPresent("email", row::getEmail)
            .map(password).toPropertyWhenPresent("password", row::getPassword)
            .map(isAdmin).toPropertyWhenPresent("isAdmin", row::getIsAdmin)
            .map(enabled).toPropertyWhenPresent("enabled", row::getEnabled)
            .map(createBy).toPropertyWhenPresent("createBy", row::getCreateBy)
            .map(updateBy).toPropertyWhenPresent("updateBy", row::getUpdateBy)
            .map(pwdResetTime).toPropertyWhenPresent("pwdResetTime", row::getPwdResetTime)
            .map(createTime).toPropertyWhenPresent("createTime", row::getCreateTime)
            .map(updateTime).toPropertyWhenPresent("updateTime", row::getUpdateTime)
            .map(language).toPropertyWhenPresent("language", row::getLanguage)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.819+08:00", comments="Source Table: sys_user")
    default Optional<User> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, user, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.819+08:00", comments="Source Table: sys_user")
    default List<User> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, user, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.82+08:00", comments="Source Table: sys_user")
    default List<User> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, user, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.82+08:00", comments="Source Table: sys_user")
    default Optional<User> selectByPrimaryKey(Long userId_) {
        return selectOne(c ->
            c.where(userId, isEqualTo(userId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.82+08:00", comments="Source Table: sys_user")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, user, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.821+08:00", comments="Source Table: sys_user")
    static UpdateDSL<UpdateModel> updateAllColumns(User row, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(userId).equalTo(row::getUserId)
                .set(deptId).equalTo(row::getDeptId)
                .set(username).equalTo(row::getUsername)
                .set(nickName).equalTo(row::getNickName)
                .set(gender).equalTo(row::getGender)
                .set(phone).equalTo(row::getPhone)
                .set(email).equalTo(row::getEmail)
                .set(password).equalTo(row::getPassword)
                .set(isAdmin).equalTo(row::getIsAdmin)
                .set(enabled).equalTo(row::getEnabled)
                .set(createBy).equalTo(row::getCreateBy)
                .set(updateBy).equalTo(row::getUpdateBy)
                .set(pwdResetTime).equalTo(row::getPwdResetTime)
                .set(createTime).equalTo(row::getCreateTime)
                .set(updateTime).equalTo(row::getUpdateTime)
                .set(language).equalTo(row::getLanguage);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.821+08:00", comments="Source Table: sys_user")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(User row, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(userId).equalToWhenPresent(row::getUserId)
                .set(deptId).equalToWhenPresent(row::getDeptId)
                .set(username).equalToWhenPresent(row::getUsername)
                .set(nickName).equalToWhenPresent(row::getNickName)
                .set(gender).equalToWhenPresent(row::getGender)
                .set(phone).equalToWhenPresent(row::getPhone)
                .set(email).equalToWhenPresent(row::getEmail)
                .set(password).equalToWhenPresent(row::getPassword)
                .set(isAdmin).equalToWhenPresent(row::getIsAdmin)
                .set(enabled).equalToWhenPresent(row::getEnabled)
                .set(createBy).equalToWhenPresent(row::getCreateBy)
                .set(updateBy).equalToWhenPresent(row::getUpdateBy)
                .set(pwdResetTime).equalToWhenPresent(row::getPwdResetTime)
                .set(createTime).equalToWhenPresent(row::getCreateTime)
                .set(updateTime).equalToWhenPresent(row::getUpdateTime)
                .set(language).equalToWhenPresent(row::getLanguage);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.822+08:00", comments="Source Table: sys_user")
    default int updateByPrimaryKey(User row) {
        return update(c ->
            c.set(deptId).equalTo(row::getDeptId)
            .set(username).equalTo(row::getUsername)
            .set(nickName).equalTo(row::getNickName)
            .set(gender).equalTo(row::getGender)
            .set(phone).equalTo(row::getPhone)
            .set(email).equalTo(row::getEmail)
            .set(password).equalTo(row::getPassword)
            .set(isAdmin).equalTo(row::getIsAdmin)
            .set(enabled).equalTo(row::getEnabled)
            .set(createBy).equalTo(row::getCreateBy)
            .set(updateBy).equalTo(row::getUpdateBy)
            .set(pwdResetTime).equalTo(row::getPwdResetTime)
            .set(createTime).equalTo(row::getCreateTime)
            .set(updateTime).equalTo(row::getUpdateTime)
            .set(language).equalTo(row::getLanguage)
            .where(userId, isEqualTo(row::getUserId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-05-03T18:00:34.823+08:00", comments="Source Table: sys_user")
    default int updateByPrimaryKeySelective(User row) {
        return update(c ->
            c.set(deptId).equalToWhenPresent(row::getDeptId)
            .set(username).equalToWhenPresent(row::getUsername)
            .set(nickName).equalToWhenPresent(row::getNickName)
            .set(gender).equalToWhenPresent(row::getGender)
            .set(phone).equalToWhenPresent(row::getPhone)
            .set(email).equalToWhenPresent(row::getEmail)
            .set(password).equalToWhenPresent(row::getPassword)
            .set(isAdmin).equalToWhenPresent(row::getIsAdmin)
            .set(enabled).equalToWhenPresent(row::getEnabled)
            .set(createBy).equalToWhenPresent(row::getCreateBy)
            .set(updateBy).equalToWhenPresent(row::getUpdateBy)
            .set(pwdResetTime).equalToWhenPresent(row::getPwdResetTime)
            .set(createTime).equalToWhenPresent(row::getCreateTime)
            .set(updateTime).equalToWhenPresent(row::getUpdateTime)
            .set(language).equalToWhenPresent(row::getLanguage)
            .where(userId, isEqualTo(row::getUserId))
        );
    }

}
